/*function area*/
var ehaier = ehaier || {};


ehaier.products = {
    init : function () {
        var that = this;
        $('.ul-sharebox').thumbox({maxThumbWidth:500});//查看缩略图
        if($('.commentsType').length){
            that._rateAnimate();//百分比
        }
    },

    _rateAnimate:function(){//百分比
        var max="bargood";
        var middle="barsoso";
        var min="barbad";

        var maxValue=0;
        var minValue=0;

        var maxIndex=0;
        var minIndex=0;

        $(".charts").each(function(i,item){
            var a=parseInt($(item).attr("w"));

            if(i==0){
                minValue=a;
                minIndex=i;
            }

            if(a>maxValue){
                maxValue=a;
                maxIndex=i;
            }else if(a<minValue){
                minValue=a;
                minIndex=i;
            }

        });

        $(".charts").each(function(i,item){
            var addStyle="";
            var divindex=parseInt($(item).attr("divindex"));
            if(divindex==maxIndex){
                addStyle=max;
            }else if(divindex==minIndex){
                addStyle=min;
            }else{
                addStyle=middle;
            }

            $(item).addClass(addStyle);
            var a=$(item).attr("w");
            $(item).animate({
                width: a+"%"
            },1000);
        });

    }
}

$("#commentsAjax").click(function(){
	var desUrl = "comment/index.html?itemId="+productId+"&&booleanIndex = 'index'";
	$.ajax({
   	    type: 'get',   
   		url:desUrl,
   		cache: false,    		
   		async:false,
   		success: function(data, status){
	     	$('#commentIndex').html(data);	
	     	$('#commentIndex').show();
	     	$('#commentAll').show();
	     	if($('.commentsType').length){
	            ehaier.products._rateAnimate();//百分比
	        }
	     	
       },
      error: function(XMLHttpRequest, textStatus, exception){
      	alert(XMLHttpRequest.status+','+XMLHttpRequest.readyState+','+textStatus);   //it will be removed after launch
          alert(msgAjaxErrorForRequest); 
      }
   });	
	
})

$("#introduce").click(function(){
	$('#commentIndex').hide();	
 	$('#commentAll').hide();
})

$("#guige").click(function(){
	$('#commentIndex').hide();	
 	$('#commentAll').hide();
})

$("#peisong").click(function(){
	$('#commentIndex').hide();	
 	$('#commentAll').hide();
})

/*use*/
$(function () {
    ehaier.products.init();
    
    /* 适配 1024 分辨率 */
    if(screen.width <= 1024){
        $(document.body).css({
            "margin-left": '-'+9.5+'%',
            "overflow-x":'hidden'
        });
    }

});